const xq = 'https://m.douban.com/rexxar/api/v2/'
const count = 8
Page({
    data:{
        start:0,
        type:'',
        id:''
    },
    onLoad(option){
        console.log(option)
        let{type,id}= option
        this.setData({
            type,
            id
        })
        wx.request({
          url: xq+option.type+'/'+option.id,
          success:res=>{
             console.log(res.data)
              let mygenres = res.data.genres.join('/')
              let myactors = res.data.actors.slice(0,3).map(v=>{
                  return v.name
              }).join('/')
              let rate = res.data.rating.value
              //console.log(rate)
              //星星个数
              let lights = 'a'.repeat(Math.floor(rate / 2))
              //半个星星个数
              let halfs = rate % 2 != 0
              //灰色星星个数
              let grays = 'a'.repeat(Math.floor((10 - rate) / 2))
              let rateText = rate && rate > 0 ? rate.toFixed(1) : "未评分"
              this.setData({
                  xq:res.data,
                  myactors,
                  mygenres,
                  rateText: rateText,
                  lights: lights,
                  halfs: halfs,
                  grays: grays
              })
          }
        })
        wx.request({
          url: xq+option.type+'/'+option.id+'/tags?count=8',
          success:res=>{
            console.log(res.data)
            let bq = res.data
            let qq = bq.tags
            bq.ttag = qq
              this.setData({bq})
          }
        })
        wx.request({
          url: xq+option.type+'/'+option.id+'/interests',
          success:res=>{
            console.log(res.data)
              this.setData({dp:res.data})
          }
        })
    },
    onReachBottom(){
        this.setData({
            start:this.data.start+count
        })
        let url = xq + this.data.type+'/'+this.data.id+'/interests?start='+this.data.start+"&count="+count
        // console.log(url)
        wx.request({
          url: url,
          success:res=>{
            //   console.log(res)
              let dp = this.data.dp
              let cc =dp.iinterest
              let jj = res.data.iinterest
              dp.iinterest = cc.concat(jj)
              this.setData({
                  dp
              })
          }
        })
    }
})